package com.wayhome.springfarmework.core.io;

import cn.hutool.core.lang.Assert;
import com.sun.org.apache.regexp.internal.RE;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.BitSet;

public class DefaultResourceLoader implements ResourceLoader{


    @Override
    public Resource getResource(String location) throws IOException {
        Assert.notNull(location, "Location must not be null");

        if (location.startsWith(CLASSPATH_PREFIX)){
            return new ClassPathResource(location.substring(CLASSPATH_PREFIX.length()));
        }else{
            try {
                URL url = new URL(location);
                return new UrlResource(url);
            } catch (MalformedURLException e) {
                return new FileSystemResource(location);
            }
        }
    }
}
